package com.whu.waterworks.action;

import java.io.InputStream;
import java.util.List;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionSupport;
import com.whu.waterworks.dto.GisTextureStationDto;
import com.whu.waterworks.dto.GisTextureWaterplantDto;
import com.whu.waterworks.model.Realtimedata;
import com.whu.waterworks.model.TWaterplantdata;
import com.whu.waterworks.model.WaterPlant;
import com.whu.waterworks.service.DataService;
import com.whu.waterworks.service.StationnumpositionService;
import com.whu.waterworks.service.WaterPlantDataService;
import com.whu.waterworks.service.WaterPlantService;
import com.whu.waterworks.util.ImageUtil;

public class GisMakeTextTureAction extends ActionSupport {
	/**
	 * 
	 */
	private static final long serialVersionUID = -2566536411405794387L;
	private StationnumpositionService stationnumpositionService;
	private DataService dataService;
	private WaterPlantService waterPlantService;
	private WaterPlantDataService waterPlantDataService;
	private String status;
	private String code;
	private InputStream station;
	private InputStream waterplant;

	public String getStationPic() {
		String path = ServletActionContext.getServletContext().getRealPath("/");
		path += "pipeline\\texture\\station.jpg";
		System.out.println(path);
		System.out.println(code);
		GisTextureStationDto dto =  new GisTextureStationDto();
		List<Realtimedata> realtimedatas = dataService
				.getAllRealTimeDataById(code.trim());
		dto.setName(stationnumpositionService.findStationById(code).getPositionname());
		if (realtimedatas != null && realtimedatas.size() > 0) {
			// 每个站点的所有类型数据
			for (Realtimedata realtimedata : realtimedatas) {
				if (realtimedata.getId().getType().contains("流量")) {
					dto.setLiuliang(realtimedata.getValue());
				} else if (realtimedata.getId().getType().contains("压力")) {
					dto.setYali(realtimedata.getValue());
				} else if (realtimedata.getId().getType().contains("浊度")) {
					dto.setZhuodu(realtimedata.getValue());
				} else if (realtimedata.getId().getType().contains("余氯")) {
					dto.setYulv(realtimedata.getValue());
				}
			}
			//station = ImageUtil.getNoDataPic(path,dto.getName());
		} 
		station = ImageUtil.drawStation(dto,path);
		return SUCCESS;
	}
	
	public String getWaterplantPic() {
		String path = ServletActionContext.getServletContext().getRealPath("/");
		path += "pipeline\\texture\\waterplant.jpg";
		System.out.println(path);
		System.out.println(code);
		
		GisTextureWaterplantDto dto = new GisTextureWaterplantDto();
		WaterPlant waterplantBean = waterPlantService.getWaterPlantById(code);
		if(waterplantBean!=null)
		{
			dto.setName(waterplantBean.getWaterPlantName());
		}
		TWaterplantdata waterplantdata = waterPlantDataService.getLastWaterPlantData(code.trim());
		
		if(waterplantdata!=null )
		{					
			
			dto.setGongshuiliang(waterplantdata.getTotalSupplyFlow());
			dto.setYulv(waterplantdata.getChlorineOut());
			dto.setZhuodu(waterplantdata.getTurbidityOut());
		}
		waterplant =ImageUtil.drawWaterplant(dto,path);
		return SUCCESS;
	}

	
	public InputStream getWaterplant() {
		return waterplant;
	}

	public void setWaterplant(InputStream waterplant) {
		this.waterplant = waterplant;
	}

	public InputStream getStation() {
		return station;
	}

	public void setStation(InputStream station) {
		this.station = station;
	}

	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	public StationnumpositionService getStationnumpositionService() {
		return stationnumpositionService;
	}

	public void setStationnumpositionService(
			StationnumpositionService stationnumpositionService) {
		this.stationnumpositionService = stationnumpositionService;
	}

	public DataService getDataService() {
		return dataService;
	}

	public void setDataService(DataService dataService) {
		this.dataService = dataService;
	}

	public WaterPlantService getWaterPlantService() {
		return waterPlantService;
	}

	public void setWaterPlantService(WaterPlantService waterPlantService) {
		this.waterPlantService = waterPlantService;
	}

	public WaterPlantDataService getWaterPlantDataService() {
		return waterPlantDataService;
	}

	public void setWaterPlantDataService(
			WaterPlantDataService waterPlantDataService) {
		this.waterPlantDataService = waterPlantDataService;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

}
